from django.db import models
from django.contrib.auth.models import User

class Feedback(models.Model):
    TYPE_CHOICES = [
        ('bug', 'Bug'),
        ('feature', 'Feature'),
        ('suggestion', 'Suggestion'),
        ('complaint', 'Complaint'),
    ]
    
    STATUS_CHOICES = [
        ('pending', 'Pending'),
        ('reviewed', 'Reviewed'),
        ('resolved', 'Resolved'),
        ('rejected', 'Rejected'),
    ]
    
    PRIORITY_CHOICES = [
        ('low', 'Low'),
        ('medium', 'Medium'),
        ('high', 'High'),
        ('critical', 'Critical'),
    ]
    
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    type = models.CharField(max_length=20, choices=TYPE_CHOICES, default='suggestion')
    title = models.CharField(max_length=200)
    content = models.TextField()
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending')
    priority = models.CharField(max_length=20, choices=PRIORITY_CHOICES, default='medium')
    admin_notes = models.TextField(blank=True)
    resolved_at = models.DateTimeField(null=True, blank=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    
    # 运营监控字段 - 对应我的页面设置与关于
    view_count = models.IntegerField(default=0, help_text="反馈查看次数")
    response_time = models.FloatField(null=True, blank=True, help_text="响应时间(小时)")
    satisfaction_score = models.IntegerField(null=True, blank=True, help_text="满意度评分(1-5)")

    def __str__(self):
        return f"{self.title} - {self.user.username}"